package com.burstly.lib.component.networkcomponent.admob;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.FrameLayout.LayoutParams;
import android.widget.RelativeLayout.LayoutParams;
import com.burstly.lib.component.AbstractAdaptor;
import com.burstly.lib.component.IBurstlyAdaptor.BurstlyAdType;
import com.burstly.lib.component.IBurstlyAdaptorListener;
import com.burstly.lib.component.IBurstlyAdaptorListener.FullscreenInfo;
import com.burstly.lib.component.networkcomponent.ClickAwareWrapper;
import com.burstly.lib.util.LoggerExt;
import com.google.ads.Ad;
import com.google.ads.AdListener;
import com.google.ads.AdRequest;
import com.google.ads.AdRequest.ErrorCode;
import com.google.ads.AdSize;
import com.google.ads.AdView;
import com.google.ads.InterstitialAd;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Map;

final class AdmobAdaptor extends AbstractAdaptor
{
  static final IBurstlyAdaptorListener.FullscreenInfo FULLSCREEN_INFO = new IBurstlyAdaptorListener.FullscreenInfo("admob", true);
  static final String NETWORK_NAME = "admob";
  private static final String TAG = AdmobAdaptor.class.getSimpleName();
  private BurstlyAdViewWrapper mAdView;
  private InterstitialAd mCachedInterstitialAd;
  private final AdmobConfigurator mConfigurator;
  private InterstitialAd mInterstitialAd;

  AdmobAdaptor(Context paramContext, String paramString)
  {
    super(paramContext, paramString);
    this.mTag = (paramString + " " + TAG);
    this.mConfigurator = new AdmobConfigurator();
  }

  private void configureAdRequest(AdRequest paramAdRequest)
  {
    this.mConfigurator.configure(paramAdRequest);
  }

  private BurstlyAdViewWrapper createImpl()
  {
    BurstlyAdViewWrapper localBurstlyAdViewWrapper = new BurstlyAdViewWrapper((Activity)getContext(), this.mConfigurator.getAdSize(), this.mConfigurator.getAdPubId());
    localBurstlyAdViewWrapper.setGravity(17);
    localBurstlyAdViewWrapper.setLayoutParams(new RelativeLayout.LayoutParams(-2, -2));
    return localBurstlyAdViewWrapper;
  }

  private View executeRequest()
  {
    this.mAdView = createImpl();
    LoggerExt localLoggerExt = LOG;
    String str = this.mTag;
    Object[] arrayOfObject = new Object[1];
    arrayOfObject[0] = this.mConfigurator.getAdPubId();
    localLoggerExt.logInfo(str, "pubID for admob: {0}", arrayOfObject);
    this.mAdView.setAdListener(new AdmobListener(this));
    AdRequest localAdRequest = new AdRequest();
    configureAdRequest(localAdRequest);
    this.mAdView.loadAd(localAdRequest);
    return wrapView(this.mAdView);
  }

  private void handleInterstitial()
  {
    this.mInterstitialAd = new InterstitialAd((Activity)getContext(), this.mConfigurator.getAdPubId());
    this.mInterstitialAd.setAdListener(new AdmobListener(this));
    AdRequest localAdRequest = new AdRequest();
    configureAdRequest(localAdRequest);
    this.mInterstitialAd.loadAd(localAdRequest);
  }

  private void handleInterstitialSuccess()
  {
    if (!this.mConfigurator.isPrefetchInterstitial())
    {
      this.mInterstitialAd.show();
      this.mInterstitialAd.stopLoading();
      return;
    }
    this.mCachedInterstitialAd = this.mInterstitialAd;
  }

  private static void stopAutoRefresh(Object paramObject)
  {
    try
    {
      Field localField = paramObject.getClass().getDeclaredField("a");
      localField.setAccessible(true);
      localField.getType().getDeclaredMethod("a", new Class[0]).invoke(localField.get(paramObject), new Object[0]);
      return;
    }
    catch (Exception localException)
    {
      LOG.logWarning(TAG, "Could not disable autorefresh. Autorefresh will be controlled from Admob server.", new Object[0]);
    }
  }

  private FrameLayout wrapView(AdView paramAdView)
  {
    ClickAwareWrapper localClickAwareWrapper = new ClickAwareWrapper(getContext(), getAdaptorListener(), getViewId(), "admob");
    localClickAwareWrapper.addView(paramAdView, new FrameLayout.LayoutParams(-2, -2, 17));
    return localClickAwareWrapper;
  }

  protected void checkParameters(Map<String, ?> paramMap)
    throws IllegalArgumentException
  {
    this.mConfigurator.initConfigurator(paramMap);
  }

  public void destroy()
  {
    super.destroy();
    if (this.mAdView != null)
    {
      this.mAdView.destroy();
      this.mAdView = null;
    }
  }

  protected View doGetNewAd()
  {
    this.mConfigurator.setPrefetchInterstitial(false);
    if (!this.mConfigurator.isInterstitial())
      return executeRequest();
    handleInterstitial();
    return null;
  }

  public IBurstlyAdaptor.BurstlyAdType getAdType()
  {
    if (this.mConfigurator.isInterstitial())
      return IBurstlyAdaptor.BurstlyAdType.INTERSTITIAL_AD_TYPE;
    return IBurstlyAdaptor.BurstlyAdType.BANNER_AD_TYPE;
  }

  public String getNetworkName()
  {
    return "admob";
  }

  public View precacheAd()
  {
    return executeRequest();
  }

  public void precacheInterstitialAd()
  {
    this.mConfigurator.setPrefetchInterstitial(true);
    handleInterstitial();
  }

  public void showPrecachedInterstitialAd()
  {
    if (this.mCachedInterstitialAd != null)
    {
      this.mCachedInterstitialAd.show();
      getAdaptorListener().didLoad("admob", true);
      this.mCachedInterstitialAd = null;
    }
  }

  public void stop()
  {
    super.stop();
    if (this.mInterstitialAd != null)
      this.mInterstitialAd.stopLoading();
    if (this.mAdView != null)
      this.mAdView.stopLoading();
  }

  public boolean supports(String paramString)
  {
    return true;
  }

  private static class AdmobListener
    implements AdListener
  {
    private final Reference<AdmobAdaptor> mAdaptor;

    AdmobListener(AdmobAdaptor paramAdmobAdaptor)
    {
      this.mAdaptor = new WeakReference(paramAdmobAdaptor);
    }

    public void onDismissScreen(Ad paramAd)
    {
      AdmobAdaptor localAdmobAdaptor = (AdmobAdaptor)this.mAdaptor.get();
      if ((localAdmobAdaptor != null) && (!localAdmobAdaptor.isStopped()))
      {
        localAdmobAdaptor.getAdaptorListener().dismissedFullscreen(AdmobAdaptor.FULLSCREEN_INFO);
        AdmobAdaptor.access$002(localAdmobAdaptor, null);
        AdmobAdaptor.access$102(localAdmobAdaptor, null);
      }
    }

    public void onFailedToReceiveAd(Ad paramAd, AdRequest.ErrorCode paramErrorCode)
    {
      AdmobAdaptor localAdmobAdaptor = (AdmobAdaptor)this.mAdaptor.get();
      boolean bool;
      IBurstlyAdaptorListener localIBurstlyAdaptorListener;
      if ((localAdmobAdaptor != null) && (!localAdmobAdaptor.isStopped()))
      {
        AdmobAdaptor.LOG.logInfo(localAdmobAdaptor.mTag, "Failed to recieve AdMob ad...", new Object[0]);
        if (localAdmobAdaptor.mConfigurator.isSuppressAdmobAutorefresh())
          AdmobAdaptor.stopAutoRefresh(paramAd);
        bool = false;
        if (paramAd != null)
        {
          InterstitialAd localInterstitialAd = localAdmobAdaptor.mInterstitialAd;
          bool = false;
          if (paramAd == localInterstitialAd)
            bool = true;
        }
        localIBurstlyAdaptorListener = localAdmobAdaptor.getAdaptorListener();
        if (paramErrorCode == null)
          break label120;
      }
      label120: for (String str = paramErrorCode.toString(); ; str = "Loading timeout.")
      {
        localIBurstlyAdaptorListener.failedToLoad("admob", bool, str);
        AdmobAdaptor.access$002(localAdmobAdaptor, null);
        AdmobAdaptor.access$102(localAdmobAdaptor, null);
        return;
      }
    }

    public void onLeaveApplication(Ad paramAd)
    {
    }

    public void onPresentScreen(Ad paramAd)
    {
      AdmobAdaptor localAdmobAdaptor = (AdmobAdaptor)this.mAdaptor.get();
      if ((localAdmobAdaptor != null) && (!localAdmobAdaptor.isStopped()))
        localAdmobAdaptor.getAdaptorListener().shownFullscreen(AdmobAdaptor.FULLSCREEN_INFO);
    }

    public void onReceiveAd(Ad paramAd)
    {
      AdmobAdaptor localAdmobAdaptor = (AdmobAdaptor)this.mAdaptor.get();
      if ((localAdmobAdaptor != null) && (!localAdmobAdaptor.isStopped()))
      {
        AdmobAdaptor.LOG.logInfo(localAdmobAdaptor.mTag, "AdMob ad recieved...", new Object[0]);
        InterstitialAd localInterstitialAd = localAdmobAdaptor.mInterstitialAd;
        boolean bool = false;
        if (paramAd == localInterstitialAd)
          bool = true;
        localAdmobAdaptor.getAdaptorListener().didLoad("admob", bool);
        if (bool)
          localAdmobAdaptor.handleInterstitialSuccess();
        if (localAdmobAdaptor.mConfigurator.isSuppressAdmobAutorefresh())
          AdmobAdaptor.stopAutoRefresh(paramAd);
        AdmobAdaptor.access$002(localAdmobAdaptor, null);
        AdmobAdaptor.access$102(localAdmobAdaptor, null);
      }
    }
  }

  private static class BurstlyAdViewWrapper extends AdView
  {
    private static final String TAG = BurstlyAdViewWrapper.class.getSimpleName();

    public BurstlyAdViewWrapper(Activity paramActivity, AdSize paramAdSize, String paramString)
    {
      super(paramAdSize, paramString);
    }

    public boolean onInterceptTouchEvent(MotionEvent paramMotionEvent)
    {
      try
      {
        boolean bool = super.onInterceptTouchEvent(paramMotionEvent);
        return bool;
      }
      catch (Exception localException)
      {
        AdmobAdaptor.LOG.logWarning(TAG, Log.getStackTraceString(localException), new Object[0]);
      }
      return true;
    }

    public boolean onKeyDown(int paramInt, KeyEvent paramKeyEvent)
    {
      try
      {
        boolean bool = super.onKeyDown(paramInt, paramKeyEvent);
        return bool;
      }
      catch (Exception localException)
      {
        AdmobAdaptor.LOG.logWarning(TAG, Log.getStackTraceString(localException), new Object[0]);
      }
      return true;
    }

    public boolean onKeyMultiple(int paramInt1, int paramInt2, KeyEvent paramKeyEvent)
    {
      try
      {
        boolean bool = super.onKeyMultiple(paramInt1, paramInt2, paramKeyEvent);
        return bool;
      }
      catch (Exception localException)
      {
        AdmobAdaptor.LOG.logWarning(TAG, Log.getStackTraceString(localException), new Object[0]);
      }
      return true;
    }

    public boolean onKeyPreIme(int paramInt, KeyEvent paramKeyEvent)
    {
      try
      {
        boolean bool = super.onKeyPreIme(paramInt, paramKeyEvent);
        return bool;
      }
      catch (Exception localException)
      {
        AdmobAdaptor.LOG.logWarning(TAG, Log.getStackTraceString(localException), new Object[0]);
      }
      return true;
    }

    public boolean onKeyShortcut(int paramInt, KeyEvent paramKeyEvent)
    {
      try
      {
        boolean bool = super.onKeyShortcut(paramInt, paramKeyEvent);
        return bool;
      }
      catch (Exception localException)
      {
        AdmobAdaptor.LOG.logWarning(TAG, Log.getStackTraceString(localException), new Object[0]);
      }
      return true;
    }

    public boolean onKeyUp(int paramInt, KeyEvent paramKeyEvent)
    {
      try
      {
        boolean bool = super.onKeyUp(paramInt, paramKeyEvent);
        return bool;
      }
      catch (Exception localException)
      {
        AdmobAdaptor.LOG.logWarning(TAG, Log.getStackTraceString(localException), new Object[0]);
      }
      return true;
    }

    public boolean onTouchEvent(MotionEvent paramMotionEvent)
    {
      try
      {
        boolean bool = super.onTouchEvent(paramMotionEvent);
        return bool;
      }
      catch (Exception localException)
      {
        AdmobAdaptor.LOG.logWarning(TAG, Log.getStackTraceString(localException), new Object[0]);
      }
      return true;
    }

    public boolean onTrackballEvent(MotionEvent paramMotionEvent)
    {
      try
      {
        boolean bool = super.onTrackballEvent(paramMotionEvent);
        return bool;
      }
      catch (Exception localException)
      {
        AdmobAdaptor.LOG.logWarning(TAG, Log.getStackTraceString(localException), new Object[0]);
      }
      return true;
    }
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.burstly.lib.component.networkcomponent.admob.AdmobAdaptor
 * JD-Core Version:    0.6.2
 */